/**
 * Copyright (c) 2012 Sean Beecroft, Permission is hereby granted, free of
 * charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy, modify,
 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 * 
 * For more information on this project and others, please visit my google code 
 * repository:
 * https://code.google.com/u/seanbeecroft@gmail.com/
 */
package javaballs;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;
import java.util.Timer;
import javax.swing.JFrame;

/**
 *
 * @author beecrofs
 */
public class Main extends JFrame implements WindowListener, ComponentListener {

    static ArrayList<Ball> vec = new ArrayList<Ball>();

    public static ArrayList<Ball> getBalls() {
        return vec;
    }

    public static void setBalls(ArrayList<Ball> v) {
        vec = v;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Main frame = new Main();
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        final G g = new G();
        Globals.app = frame;
        Globals.g = g;
        frame.setTitle("javaballs - copyright (c) 2010 Sean Beecroft");
        frame.setSize(new Dimension(700, 700));
        frame.addComponentListener(frame);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(g);
        frame.addWindowListener(frame);
        g.addMouseListener(g);
        frame.setVisible(true);
        ArrayList<Ball> balls = new ArrayList<Ball>();

        Timer t = new Timer();
        P task = new P(g);
        Engine task2 = new Engine();
        CollisionDetectionTask task3 = new CollisionDetectionTask();
        t.scheduleAtFixedRate(task, 0, 15);
        t.scheduleAtFixedRate(task2, 0, 15);
        t.scheduleAtFixedRate(task3, 0, 16);
    }

    public void windowOpened(WindowEvent e) {
    }

    public void windowClosing(WindowEvent e) {
    }

    public void windowClosed(WindowEvent e) {
    }

    public void windowIconified(WindowEvent e) {
    }

    public void windowDeiconified(WindowEvent e) {
    }

    public void windowActivated(WindowEvent e) {
    }

    public void windowDeactivated(WindowEvent e) {
    }

    public void componentResized(ComponentEvent e) {
        System.out.println("resized");
        Globals.g.clear();
    }

    public void componentMoved(ComponentEvent e) {
    }

    public void componentShown(ComponentEvent e) {
    }

    public void componentHidden(ComponentEvent e) {
    }
}
